﻿using Microsoft.EntityFrameworkCore;
using ProgrammingEducationSystem.DbConfig;
using ProgrammingEducationSystem.Models;

namespace ProgrammingEducationSystem.Repository.IRepository
{
    public class StuAndClassRepository : BaseRepository<StuAndClass>, IStuAndClassRepository
    {
        public StuAndClassRepository(AppDbCtx appDbCtx) : base(appDbCtx)
        {
        }

        public async Task DeleteByClassIdAsync(Guid classId)
        {
            _appDbCtx.StuAndClasses.RemoveRange(
                 _appDbCtx.StuAndClasses.Where(sc => sc.ClassId == classId).ToList()
                ) ;
        }

        public async Task<List<StuAndClass>> GetByClassIdAsync(Guid classId)
        {
            return await _appDbCtx.StuAndClasses.Where(sc => sc.ClassId == classId).ToListAsync();
        }

        public async Task<List<StuAndClass>> GetByStudentIdAsync(string id)
        {
            return await _appDbCtx.StuAndClasses.Where(sc=> sc.StudentId== id).ToListAsync();
        }
    }
}
